package com.sjb.sixteen_journey_backend.controller;


import com.sjb.sixteen_journey_backend.common.R;
import com.sjb.sixteen_journey_backend.entity.MyMap;
import com.sjb.sixteen_journey_backend.entity.MyTime;
import com.sjb.sixteen_journey_backend.entity.dto.MyMapDto;
import com.sjb.sixteen_journey_backend.entity.vo.MyMapVo;
import com.sjb.sixteen_journey_backend.service.IMyMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 我的地图表
 *
 * @author jcz
 * @since 2024-07-25
 */
@RestController
@RequestMapping("/my-map")
public class MyMapController {

    @Autowired
    private IMyMapService myMapService;

    /**
     * 添加地图
     *
     * @param myMapDto
     * @return
     */
    @PostMapping("/addMyMap")
    public R<MyMap> addMyMap(@RequestBody MyMapDto myMapDto) {
        return myMapService.addMyMap(myMapDto);
    }

    /**
     * 删除地图
     *
     * @param myMapId
     * @return
     */
    @DeleteMapping("/removeMyMap/{id}")
    public R removeMyMap(@PathVariable("id") Integer myMapId) {
        return myMapService.removeMyMap(myMapId);
    }

    /**
     * 通过id查找地图
     *
     * @param id
     * @return
     */
    @GetMapping("/showMapById/{id}")
    public R<MyMap> showMapById(@PathVariable("id") Integer id) {
        return myMapService.showMapById(id, true);
    }



    /**
     * 修改地图权限为所有人可见或仅自己可见
     *
     * @param id       地图id
     * @param isPublic 是否所有人可见
     * @return
     */
    @PatchMapping("/changeAuthorityIsPublic/{id}")
    public R changeAuthorityIsPublic(@PathVariable("id") Integer id,
                                     @RequestParam Boolean isPublic) {
        return myMapService.changeAuthorityIsPublic(id, isPublic);
    }


    /**
     * 修改地图名
     *
     * @param id   地图id
     * @param name 地图名
     * @return
     */
    @PatchMapping("/changeMapName/{id}")
    public R<MyMap> changeMapName(@PathVariable("id") Integer id,
                                  @RequestParam String name) {
        return myMapService.changeMapName(id, name);
    }

    /**
     * 修改地图封面
     *
     * @param id   地图id
     * @param file 图片
     * @return
     */
    @PostMapping("/changeMapAvatar/{id}")
    public R<MyMap> changeMapAvatar(@PathVariable("id") Integer id,
                                    @RequestParam MultipartFile file) {
        return myMapService.changeMapAvatar(id, file);
    }

    /**
     * 修改地图备注
     *
     * @param id      地图id
     * @param content 地图备注内容
     * @return
     */
    @PatchMapping("/changeMapRemarks/{id}")
    public R<MyMap> changeMapRemarks(@PathVariable("id") Integer id,
                                     @RequestParam String content) {
        return myMapService.changeMapRemarks(id, content);
    }

    /**
     * 获取所有地图
     *
     * @return
     */
    @GetMapping("/showAllMap")
    public R<List<MyMapVo>> showAllMap() {
        return myMapService.showAllMap();
    }

    /**
     * 获取城市相关的地图
     *
     * @return
     */
    @GetMapping("/showCityMap/{city}")
    public R<List<MyMapVo>> showCityMap(@PathVariable("city") String city) {
        return myMapService.showCityMap(city);
    }

    /**
     * 获取当前登录用户地图
     *
     * @return
     */
    @GetMapping("/showMapByUserId")
    public R<List<MyMapVo>> showMapByUserId() {
        return myMapService.showMapByUserId();
    }

    /**
     * 获取某用户的所有公开的'我的此刻'
     * @param id 用户id
     * @return
     */
    @GetMapping("/showPublicMapById/{id}")
    public R<List<MyMapVo>> showPublicMapById(@PathVariable("id") Integer id) {
        return myMapService.showPublicMapById(id);
    }

    /**
     * 通过关键字搜索公开地图
     * @param keyWords 关键字
     * @return
     */
    @GetMapping("/showMapByKeyWords")
    public R<List<MyMapVo>> showPublicMapByKeyWords(@RequestParam String keyWords){
        return myMapService.showPublicMapByKeyWords(keyWords);
    }
}
